package com.example.test06thread.callable;

import java.util.concurrent.CountDownLatch;

/**
 * @Author: fxy
 * @Date: 2022/05/27/9:56
 * @Description:
 */
public class CountDownLatchTest {
    public static void main(String[] args) throws InterruptedException {
        //总数是10，必须执行任务时使用
        CountDownLatch countDownLatch = new CountDownLatch(10);
        for (int i=0;i<10;i++){
            new Thread(()->{
                System.out.println(Thread.currentThread().getName()+"出队");
                //数量减一，每个线程执行完毕
                countDownLatch.countDown();
            }).start();
        }
        //必须等待计数器归零了，才能继续往下执行
        countDownLatch.await();
        System.out.println("队列清空了");
    }
}
